#!/usr/bin/env python
# -*- coding: utf-8 -*-

from flask_httpauth import HTTPBasicAuth, HTTPTokenAuth, MultiAuth

class Auth(object):
   basic_auth = None
   token_auth = None
   multi_auth = None
   @staticmethod
   def getInstance():
     import threading
     #线程安全
     mylock = threading.RLock()
     mylock.acquire()
     if not Auth.basic_auth:
         Auth.basic_auth = HTTPBasicAuth()
     if not Auth.token_auth:
         Auth.token_auth = HTTPTokenAuth(scheme='Bearer')
     if not Auth.multi_auth:
         Auth.multi_auth = MultiAuth(Auth.basic_auth, Auth.token_auth)
     mylock.release()

     return Auth.basic_auth, Auth.token_auth, Auth.multi_auth